package com.usian.admin.controller;

import com.usian.admin.service.AdChannelService;
import com.usian.apis.admin.AdChannelControllerApi;
import com.usian.model.admin.dtos.ChannelDto;
import com.usian.model.admin.pojos.AdChannel;
import com.usian.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/channel")
@Api(value = "后台管理频道模块" ,tags = "channel",description = "频道管理模块的增删改查")
public class AdChannelController implements AdChannelControllerApi {

    @Autowired
    private AdChannelService adChannelService;

    /**
     * 频道查询
     *
     * @param dto
     * @return
     */
    @Override
    @PostMapping("/list")
    @ApiOperation(value = "频道查询",notes = "频道分页查询")
    @ApiImplicitParam(name = "dto",type ="ChannelDto",value = "频道名称")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "dto",type ="ChannelDto",value = "频道名称"),
//            @ApiImplicitParam(name = "num",type ="ChannelDto",value = "数量")
//    })
    public ResponseResult findByNameAndPage( @RequestBody ChannelDto dto) {
        return adChannelService.findByNameAndPage(dto);
    }

    /**
     * 频道保存
     *
     * @param adChannel
     * @return
     */
    @Override
    @RequestMapping("/save")
    @ApiOperation(value = "频道保存",notes = "频道保存功能")
    @ApiImplicitParam(name = "adChannel",type ="AdChannel",value = "按频道传递对象保存")
    public ResponseResult saveAdChannel(@RequestBody AdChannel adChannel) {
        return adChannelService.saveAdChannel(adChannel);
    }

    /**
     * 修改频道
     *
     * @param adChannel
     * @return
     */
    @Override
    @RequestMapping("/update")
    public ResponseResult update(@RequestBody AdChannel adChannel) {
        return adChannelService.update(adChannel);
    }

    /**
     * 删除指定id频道
     *
     * @param id
     * @return
     */
    @Override
    @GetMapping("/del/{id}")
    public ResponseResult deleteByChannelId(@PathVariable Integer id) {
        AdChannel adChannel =new AdChannel();
        adChannel.setId(id);
        return adChannelService.deleteByChannelId(adChannel);
    }

    @Override
    @GetMapping("/channels")
    public ResponseResult findAll() {
        List<AdChannel> list = adChannelService.list();
        return  ResponseResult.okResult(list);
    }


}
